﻿window.currentTime1 = 0
var timer = new (function () {
    var $stopwatch, // Stopwatch element on the page
      incrementTime = 50, // Timer speed in milliseconds
        // Current time in hundredths of a second
        updateTimer = function () {
            $stopwatch.html(formatTime((getNewScenario().gameLength) - window.currentTime1));
            window.currentTime1 += incrementTime;
        },
        init = function () {
            $stopwatch = $('#time');
            timer.Timer = $.timer(updateTimer, incrementTime, false);
        };
    this.resetStopwatch = function () {
        window.currentTime1 = 0;
        this.Timer.stop().once();
    };
    $(init);
});

function formatTime(time) {
    var min = parseInt(time / 60000),
        sec = parseInt(time / 1000) - (min * 60);
        //hundredths = pad(time - (sec * 100) - (min * 6000), 2);
    return (min > 0 ? pad(min, 2) : "00") + ":" + pad(sec, 2);
}

function pad(number, length) {
    var str = '' + number;
    while (str.length < length) { str = '0' + str; }
    return str;
}